package com.redis;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import javax.swing.*;

@SpringBootApplication
@MapperScan("com.redis.dao")
public class RedisTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(RedisTestApplication.class);
    }

//
//    @Configuration
//    @EnableCaching //开启注解
//    public class RedisTempConfig {
//        // 配置序列化
//        @Bean // LettuceConnectionFactory
//        public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
//
//            System.out.println(redisConnectionFactory);
//            RedisTemplate<String, Object> template = new RedisTemplate<>();
//            //spring 2.x 默认使用的redisclient使用LettuceConnectionFactory 可以实现setDataBase切库功能
//            //redisConnectionFactory.setDatabase(1);
//            template.setKeySerializer(new StringRedisSerializer());
//            template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
//            template.setHashKeySerializer(RedisSerializer.string());
//            template.setHashValueSerializer(RedisSerializer.java());
//            template.setConnectionFactory(redisConnectionFactory);
//            template.afterPropertiesSet();
//            return template;
//        }
//    }

}
